layui.define(['layer', 'jquery'], function (exports) {
    const layer = parent.layer;
    const $ = layui.jquery;
    exports("conf", {
        view: {
            //网站标题
            title: '<b class="biz-font-color" ">Unify</b>  Admin LayUI',
            //网站入口
            entry: "/system/index/index",
            //图标
            favicon: "/img/logo.png",
            //模板地架
            layout: "/layout",
            //登录路由
            login: '/login',
            //主题
            theme: {
                curr: layui.data('layout_theme').curr || "blue",
                all: {
                    "black": "黑色",
                    "blue": "蓝色",
                    "dark_blue": "深蓝色",
                }
            },
        },
        api: {
            mock: {
                //开启Mock
                use: true,
                //Mock路径
                path: "/mock/api",
            },
            //系统内置的api
            url: {
                upload: "/system/system/upload",
            },
            //返回状态值
            code: {
                //成功
                success: 200,
                //错误
                error: 500,
                //拒绝
                denied: 403,
            },
            //请求前预处理
            before: function (params) {

                const baseUrl = location.origin;
                params.url = baseUrl + params.url;
                //
                // if(params.method == "POST"){
                //     params.dataType = "JSON";
                //     params.contentType = 'application/json;charset=utf-8';
                //     params.data = JSON.stringify(params.data);
                // }

                return params;
            },
            //请求响应后
            after: function (response, request, resolve, reject) {
                switch (response.code) {
                    case this.code.success:
                        resolve(response);
                        break;
                    case this.code.error:
                        layer.msg(response.msg);
                        reject(response);
                        break;
                    case this.code.denied:
                        localStorage.removeItem("user_token");
                        layer.msg(response.msg);
                        location.reload();
                        break;
                    default:
                        layer.msg(request.url + "返回结构异常");
                        reject();
                }
            },
            token: {
                get: function () {
                    return localStorage.getItem("user_token");
                },
                set: function (token) {
                    localStorage.setItem("user_token", token);
                },
                remove: function () {
                    localStorage.removeItem("user_token")
                }
            },
        },
        authority: {
            getInfo: function () {
                return {
                    id: localStorage.getItem("user_role_id"),
                    name: localStorage.getItem("user_role_name"),
                    auths: localStorage.getItem("user_role_auths"),
                }
            }
        }
    });
});